<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: any object</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_any.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">any object </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptany/</p>
<p>The <code>any</code> type is a generic container that can hold any value. It is a reference type.</p>
<p>The type is registered with <code>RegisterScriptAny(asIScriptEngine*)</code>.</p>
<h2><a class="anchor" id="doc_addon_any_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CScriptAny
{
<span class="keyword">public</span>:
  <span class="comment">// Constructors</span>
  CScriptAny(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine);
  CScriptAny(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> refTypeId, <a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine);

  <span class="comment">// Memory management</span>
  <span class="keywordtype">int</span> AddRef() <span class="keyword">const</span>;
  <span class="keywordtype">int</span> Release() <span class="keyword">const</span>;

  <span class="comment">// Copy the stored value from another any object</span>
  CScriptAny &amp;operator=(<span class="keyword">const</span> CScriptAny&amp;);
  <span class="keywordtype">int</span> CopyFrom(<span class="keyword">const</span> CScriptAny *other);

  <span class="comment">// Store the value, either as variable type, integer number, or real number</span>
  <span class="keywordtype">void</span> Store(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> refTypeId);
  <span class="keywordtype">void</span> Store(<a class="code" href="angelscript_8h.html#aa8044b56ee56e2350b06f1e7207b43df" title="64 bit integer">asINT64</a> &amp;value);
  <span class="keywordtype">void</span> Store(<span class="keywordtype">double</span> &amp;value);

  <span class="comment">// Retrieve the stored value, either as variable type, integer number, or real number</span>
  <span class="keywordtype">bool</span> Retrieve(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> refTypeId) <span class="keyword">const</span>;
  <span class="keywordtype">bool</span> Retrieve(<a class="code" href="angelscript_8h.html#aa8044b56ee56e2350b06f1e7207b43df" title="64 bit integer">asINT64</a> &amp;value) <span class="keyword">const</span>;
  <span class="keywordtype">bool</span> Retrieve(<span class="keywordtype">double</span> &amp;value) <span class="keyword">const</span>;

  <span class="comment">// Get the type id of the stored value</span>
  <span class="keywordtype">int</span> GetTypeId() <span class="keyword">const</span>;
};
</pre></div><h2><a class="anchor" id="doc_addon_any_2"></a>
Public script interface</h2>
<pre>
  class any
  {
    any();
    any(? &amp;in value);</pre><pre>    void store(? &amp;in value);
    void store(int64 &amp;in value);
    void store(double &amp;in value);</pre><pre>    bool retrieve(? &amp;out value) const;
    bool retrieve(int64 &amp;out value) const;
    bool retrieve(double &amp;out value) const;
  }
</pre><h2><a class="anchor" id="doc_addon_any_3"></a>
Example usage</h2>
<p>In the scripts it can be used as follows:</p>
<pre>
  int value;
  obj object;
  obj @handle;
  any a,b,c;
  a.store(value);      // store the value
  b.store(@handle);    // store an object handle
  c.store(object);     // store a copy of the object</pre><pre>  a.retrieve(value);   // retrieve the value
  b.retrieve(@handle); // retrieve the object handle
  c.retrieve(object);  // retrieve a copy of the object
</pre><p>In C++ the type can be used as follows:</p>
<div class="fragment"><pre class="fragment">CScriptAny *myAny;
<span class="keywordtype">int</span> typeId = engine-&gt;<a class="code" href="classas_i_script_engine.html#ad1f6fecb0f53fd7966736b01f65c3dcb" title="Returns a type id by declaration.">GetTypeIdByDecl</a>(<span class="stringliteral">&quot;string@&quot;</span>);
CScriptString *str = <span class="keyword">new</span> CScriptString(<span class="stringliteral">&quot;hello world&quot;</span>);
myAny-&gt;Store((<span class="keywordtype">void</span>*)&amp;str, typeId);
myAny-&gt;Retrieve((<span class="keywordtype">void</span>*)&amp;str, typeId);
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
